package com.ccys.db.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LCJ
 * @Date: 2020/10/20 15:06
 * @Description: 用于向Mapper传递参数使用
 */
@Data
public class Where {

    /**
     * 查询条件（不用写and）
     */
    private List<String> whereList;

    /**
     * 分组字段
     */
    private String groupBy;

    /**
     * 排序字段
     */
    private String orderBy;

    /**
     * 结果范围
     */
    private String limit;



    public Where(){}

    public Where(String orderBy){
        new Where(null,orderBy);
    }

    public Where(String groupBy, String orderBy){
        new Where(groupBy,orderBy,null);
    }

    public Where(String groupBy, String orderBy, String limit){
        this.groupBy = groupBy;
        this.orderBy = orderBy;
        this.limit = limit;
    }

    public void addWhere(String whereStr){
        if(this.whereList == null){
            this.whereList = new ArrayList<>();
        }
        this.whereList.add(whereStr);
    }

    public void clear(){
        this.whereList.clear();
        this.groupBy = null;
        this.orderBy = null;
        this.limit = null;
    }


}
